Skip to content

Configure Git Bash shell profiles during Windows install#522

Open
svarlamov wants to merge 3 commits intomainfrom
devin/1771029053-git-bash-windows-support
Open

Configure Git Bash shell profiles during Windows install#522
svarlamov wants to merge 3 commits intomainfrom
devin/1771029053-git-bash-windows-support

Conversation

@svarlamov
Copy link
Member

@svarlamov svarlamov commented Feb 14, 2026

Configure Git Bash shell profiles during Windows install

Summary

Fixes #517. Git Bash (MSYS2/MinGW) prepends /mingw64/bin to PATH during its own shell initialization, which shadows the git-ai shim even when the Windows PATH has been correctly set by Set-PathPrependBeforeGit. This adds a new section to install.ps1 that writes export PATH="$HOME/.git-ai/bin:$PATH" into the user's ~/.bashrc or ~/.bash_profile, mirroring what install.sh already does for Unix shells.

The new block:

  1. Detects Git for Windows by checking common install paths (Program Files, Program Files (x86), LocalAppData\Programs), guarding each path against null env vars
  2. Finds existing .bashrc or .bash_profile (or creates .bashrc if neither exists)
  3. Checks for an existing .git-ai/bin marker to avoid duplicate entries
  4. Appends the PATH export using BOM-less UTF-8 encoding (via [System.IO.File]::AppendAllText with UTF8Encoding($false))
  5. Wraps everything in try/catch so a failure here never blocks the rest of the install

Updates since last revision

  • Fixed UTF-8 BOM issue: replaced Add-Content -Encoding UTF8 with [System.IO.File]::AppendAllText() using UTF8Encoding($false) to avoid writing a BOM that would cause command not found errors in bash on PowerShell 5.1.
  • Fixed null env var issue: Join-Path calls for Git Bash detection paths are now guarded with if checks so a null ProgramFiles(x86) (e.g. on 32-bit Windows) doesn't abort the entire Git Bash config block under Set-StrictMode.

Review & Testing Checklist for Human

  • Test on a real Windows machine with Git Bash installed — this change is entirely in PowerShell and cannot be verified by the Rust test suite or Linux CI. Run the installer, then open Git Bash and confirm which git resolves to ~/.git-ai/bin/git (not /mingw64/bin/git)
  • Verify no UTF-8 BOM in created .bashrc — the code now uses UTF8Encoding($false) + AppendAllText, but confirm the written file has no BOM bytes (EF BB BF) at the start, especially when .bashrc is newly created (no pre-existing file)
  • Test idempotency — run the installer twice and confirm the PATH export is not duplicated in .bashrc
  • Test with no existing .bashrc — confirm the installer creates .bashrc and the export line is correct. Consider whether creating .bashrc when a user has never used Git Bash is desirable, or if this should only append to existing files

Notes

  • Git Bash detection only covers standard Git for Windows install paths. Custom locations (Scoop, Chocolatey portable, etc.) won't be detected, but the code simply skips configuration in that case — no harm done.
  • No admin permissions required — writes only to user-scoped files (%USERPROFILE%\.bashrc / .bash_profile).
  • Link to Devin run
  • Requested by @svarlamov

Git Bash (MSYS2/MinGW) prepends /mingw64/bin to PATH during shell
initialization, which shadows the git-ai shim even when the Windows
PATH has been correctly configured. Fix this by detecting Git for
Windows installations and writing an export PATH line to ~/.bashrc
or ~/.bash_profile, mirroring what install.sh already does for Unix
shells.

Closes #517

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
@devin-ai-integration
Copy link
Contributor

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@git-ai-cloud-dev
Copy link

No AI authorship found for these commits. Please install git-ai to start tracking AI generated code in your commits.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

devin-ai-integration[bot]

This comment was marked as resolved.

@svarlamov
Copy link
Member Author

review devin feedback

PowerShell 5.1's Add-Content -Encoding UTF8 writes a UTF-8 BOM that
causes 'command not found' errors in bash. Use .NET's
UTF8Encoding(false) + AppendAllText instead to avoid the BOM.

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
devin-ai-integration[bot]

This comment was marked as resolved.

@svarlamov
Copy link
Member Author

review devin feedback

On 32-bit Windows, env vars like ProgramFiles(x86) may be null,
causing Join-Path to throw under StrictMode before the null-guard
in the loop could run. Build the array conditionally instead.

Co-Authored-By: Sasha Varlamov <sasha@sashavarlamov.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ensure Git AI properly tracks git events from Windows git bash

2 participants